package com.zhuzi.repository;

import com.zhuzi.entity.ThsNewEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author zhuzi
 * 2022/8/2 10:16
 */
@Repository
public interface ThsNewEntityRepository extends JpaRepository<ThsNewEntity, Long>, JpaSpecificationExecutor<ThsNewEntity> {
    /**
     * 根据发布时间查询
     *
     * @param localDateTime 发布时间
     */
    @Query("select t from ThsNewEntity t where t.publishTime >= ?1")
    List<ThsNewEntity> findByPublishTimeGreaterThanEqual(LocalDateTime localDateTime);

    /**
     * 找到之间发布时间
     *
     * @param publishTimeStart 发布时间开始
     * @param publishTimeEnd   发布时间结束
     * @return {@link List}<{@link ThsNewEntity}>
     */
    @Query("select t from ThsNewEntity t where t.publishTime between ?1 and ?2")
    List<ThsNewEntity> findByPublishTimeBetween(LocalDateTime publishTimeStart, LocalDateTime publishTimeEnd);
}
